<?php
namespace Home\Model;
use Think\Model;
class MoodModel extends Model{
	public function addMode($data){
		if(!empty($data)){
			$data['hits']=0;
			$data['create_time']=date('Y-m-d H:i:s');
			$moodInfo=$this->add($data);
			$where="m.id=$moodInfo";
			$join="left join __PERSONAL__ p on m.uid=p.uid";
			$fleld="m.*,p.user_tx,p.nickname,";
			$moodList= $this->alias('m')
                                        ->field($fleld)
                                        ->where($where)
                                        ->join($join)
                                        ->order('m.id desc')
                                        ->find();
			if($moodList){
				return $moodList;
			}else{
				return false;
			}
		}
	}
	public function dasdsa(){
	    
	}
        //查看全部是我好友的动态
	public function hasMood($uid){
		$where="m.uid=$uid";
		$join="left join __PERSONAL__ p on m.uid=p.uid";
		$fleld="m.*,p.user_tx,p.nickname";
		$moodList= $this->alias('m')
                        ->field($fleld)
                        ->join($join)
                        ->order("m.create_time desc")
                        ->select();
        foreach($moodList as $k=>$v){
        	//查看所有留言 
            $list= D('moodreply')->hasreply($v['id']);
            //查看所有赞
            $zanList = D('Dianzan')->contzan($v['id']);
            if($zanList){
            	$moodList[$k]['zan']=$zanList;
            }
            if($list){
                $moodList[$k]['hf']=$list;
            }
        	foreach($moodList[$k]['zan'] as $ko=>$vo){
        		if($vo['uid'] == session('user_id')){
        			$moodList[$k]['iszan']=1;
        		}else if(empty($vo)){
        			$moodList[$k]['iszan']=2;
        		}
        	}
        }
		if($moodList){
			return $moodList;
		}else{
			return false;
		}
	}
        
}
?>